package com.itheima.reggie_auto.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie_auto.entity.SetmealDish;
import com.itheima.reggie_auto.mapper.SetmealDishMapper;
import com.itheima.reggie_auto.service.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealDishServiceImpl implements SetmealDishService {

    @Autowired
    private SetmealDishMapper setmealDishMapper;


    @Override
    public void saveSetmealDish(List<SetmealDish> setmealDishes) {
        for (SetmealDish setmealDish : setmealDishes) {
            setmealDishMapper.insert(setmealDish);
        }
    }

    @Override
    public void deleteBySetmealIds(List<Long> ids) {
        LambdaQueryWrapper<SetmealDish> dishLqw = new LambdaQueryWrapper<>();
        dishLqw.in(SetmealDish::getSetmealId,ids);
        setmealDishMapper.delete(dishLqw);
    }

    @Override
    public List<SetmealDish> getBySetmealId(Long id) {
        LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SetmealDish::getSetmealId,id);
        List<SetmealDish> setmealDishes = setmealDishMapper.selectList(lqw);
        return setmealDishes;
    }

    @Override
    public Integer getByDishIds(List<Long> ids) {
        LambdaQueryWrapper<SetmealDish> setmeallqw = new LambdaQueryWrapper<>();
        setmeallqw.in(SetmealDish::getDishId,ids);
        return setmealDishMapper.selectCount(setmeallqw);
    }

    @Override
    public SetmealDish getByDishId(Long dishId) {
        LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SetmealDish::getDishId,dishId);
        return setmealDishMapper.selectOne(lqw);
    }
}
